$(function(){
	$('.good_header img').bind('click',function(){
		window.location.href = document.referrer; //返回上一页并刷新
	});
	// 轮播图
	$.ajax({
		type:"post",
		url:"http://a.91jfk.com/Product/Pic/index",
		async:true,
		data:{
			classify:1
		},
		dataType:'json',
		success:function(res){
			if(res.code == '1'){
				var msg = res.msg;
				var imgArr = [];
				for(var i = 0;i < msg.length;i++){
					imgArr.push(msg[i].pic);
				}
				// 轮播图
				var Swiper = new SwiperLunBo();
				Swiper.carousel(imgArr).swiper().changeLunBo(imgArr);		//changeLunBo方法只能在swiperLunBo方法之后调用
			}else{
				console.log(123);
			}
		},
		error:function(err){
			console.log(err);
		}
	});

    //进入页面加载数据
    $.ajax({
        url:"http://a.91jfk.com/Product/Pointshop/goods_list?type=1",
        type:'get',
        dataType:'json',
        success:function (res) {
            console.log(res);
            if(res.code =="1"){
                var msg = res.message;
                for(var i = 0;i < msg.length;i++){
					pageShow(msg[i].id,res.nowpage,msg[i].pname,msg[i].introduce,msg[i].show_pic,msg[i].low_price);
					$('img.lazy'+res.nowpage).lazyload({
						placeholder:"/Public/Product/img/loading2.gif",
						effect: "fadeIn",
						container: $(".good_listBox")
					});
                }
            }else{
                console.log(res.message);
            }
        },
        error:function (err) {
            console.log(err);
        }
    });

    //展示数据的方法
    function pageShow(id,j,title,introduce,src,newPrice) {
        var listBox = $(".good_listBox");
        var listRow = $('<div class="list_row"></div>');
        var Input = $('<input type="hidden" value="'+ id +'">');
        var listLt = $('<div class="list_left"><img class="IMG lazy'+ j +'" src="/Public/Product/img/loading2.gif" data-original="'+ src +'" alt=""></div>');
        var listRt = $('<div class="list_right"><p class="goodLisr_title">'+ title +'</p><p class="goodLisr_att">'+ introduce+'</p><p class="goodLisr_price"><span class="now">¥'+ newPrice +'</span></p><p class="fast_buy">立即抢购</p></div>');
        listRow.append(Input).append(listLt).append(listRt);
        listBox.append(listRow);
    }

    // 点击列表项跳转详情界面
    $(document).on("click",".list_row",function(){
        console.log("跳转");
        var id = $(this).find("input[type=hidden]").val();
        console.log(id);
        window.location.href = "point_shop_goodDetail.html?id=" + id;
    });
    
    // 点击立即购买跳转购买界面
    $('body').on("click",".fast_buy",function(event){
	    //event.stopPropagation();	//阻止事件冒泡
	    /*$.ajax({
	     url:'',
	     type:'get',
	     cache:false,
	     dataType:'json',
	     success:function(res) {
	     var data = JSON.pase(res);
	     if(data.code =="1"){
	     window.location.href = '';
	     }else{
	     console.log(data.msg);
	     }
	     },
	     error : function(err) {
	     console.log(err);
	     }
	     });//ajax结束*/
	});//点击事件结束
});